using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Reviews
/// </summary>
public class Reviews
{
	public Reviews()
	{		
	}
	public System.Collections.IEnumerable GetReviews(int ProductID)
	{
		System.Data.SqlClient.SqlDataAdapter reviewAdapter = new System.Data.SqlClient.SqlDataAdapter
			("SELECT ProductID, ReviewerName, EmailAddress, ReviewDate, Rating, Comments FROM Production.ProductReview WHERE ProductID=" + ProductID , ConfigurationManager.ConnectionStrings["AdvWorks"].ConnectionString);
		DataSet dsReviews = new DataSet("Reviews");
		reviewAdapter.Fill(dsReviews, "ProductReview");
		return ((dsReviews.Tables["ProductReview"]) as System.ComponentModel.IListSource).GetList();

	}
	public void AddReview(string ProductID, string ReviewerName, string EmailAddress, string ReviewDate, string Rating, string Comments)
	{
		System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["AdvWorks"].ConnectionString);
		sqlConn.Open();
		System.Data.SqlClient.SqlCommand reviewAdder = new System.Data.SqlClient.SqlCommand(
			"INSERT Production.ProductReview (ProductID, ReviewerName, EmailAddress, ReviewDate, Rating, Comments)"
			+ " VALUES ('" + ProductID + "','" + ReviewerName + "','" + EmailAddress + "','" + DateTime.Now + "','" + Rating + "','" + Comments + "')", sqlConn);
		reviewAdder.ExecuteNonQuery();
		
	}
}
